package com.baiqian.doupo.item;

import com.baiqian.doupo.Utils;
import com.baiqian.doupo.modgroup.DouPoModGroup;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

public abstract class MoHe extends Item{
    public MoHe() {
        super(new Properties().group(DouPoModGroup.douPoMoHeGroup));
    }

    /**将List代表的物品塞入nbt*/
    public static CompoundNBT getNbtFromList(List<ItemStack> list,CompoundNBT compoundNBT,int list_num, List<Integer> making_tick, List<Double> making_point){
        compoundNBT.putInt("MoHe"+list_num+":"+"num",list.size());
        for(int i=0;i<list.size();++i){
            Item item = list.get(i).getItem();
            if(TunMuHuDeMoHe.class.equals(item.getClass())){
                compoundNBT.putInt("MoHe"+list_num+":"+i,1);
            }
            if(list_num==1){
                try {
                    compoundNBT.getInt("MoHe" + list_num + ":" + i);
                    compoundNBT.putInt("MoHe" + list_num + ":" + i + ":" + "making_tick", making_tick.get(i));
                    compoundNBT.putDouble("MoHe" + list_num + ":" + i + ":" + "making_point", making_point.get(i));
                } catch (Exception e) {
                    LogManager.getLogger().info("noMoHe");
                }
            }
        }
        return compoundNBT;
    }

    /**将nbt的物品录入List*/
    public static List<ItemStack> getListFromNbt(CompoundNBT compoundNBT,int list_num, List<Integer> making_tick, List<Double> making_point){
        List<ItemStack> itemStacks = new ArrayList<>();
        int size = compoundNBT.getInt("MoHe"+list_num+":"+"num");
        for(int i=0;i<size;++i){
            int num = compoundNBT.getInt("MoHe"+list_num+":"+i);
            boolean flag = true;
            switch (num){
                case 1:itemStacks.add(new ItemStack(ItemRegistry.tun_mu_hu_de_mo_he.get()));break;
                default:flag=false;
            }
            if(flag&&list_num==1){
                making_tick.add(compoundNBT.getInt("MoHe"+list_num+":"+i+":"+"making_tick"));
                making_point.add(compoundNBT.getDouble("MoHe"+list_num+":"+i+":"+"making_point"));
            }
        }
        return itemStacks;
    }



    /**获取激活温度*/
    public abstract double getBeActivateTemprature();
    /**获取销毁温度*/
    public abstract double getBeRemoveTemprature();
    /**获取最大激活时间tick*/
    public abstract double getBeActivateMaxTick();
    /**获取激活点数*/
    public abstract double getBeActivatePoint();

    /**
     * 魔核属性总数
     * <p>0 无§7</p>
     * <p>1 火§e</p>
     * <p>2 风§3</p>
     * <p>3 木§2</p>
     * <p>4 水§9</p>
     * <p>5 冰§b</p>
     * <p>6 土§g</p>
     * <p>7 岩§6</p>
     * <p>8 沙§e</p>
     * <p>9 雷§5</p>
     * <p>10暗§8</p>
     */
    public abstract byte getAttr();

    /**属性*/
    public abstract byte getLevel();

    @OnlyIn(Dist.CLIENT)
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
        tooltip.add(new TranslationTextComponent(this.getTranslationKey() + ".1"));
        tooltip.add(new TranslationTextComponent(this.getTranslationKey() + ".2"));
        tooltip.add(ITextComponent.getTextComponentOrEmpty(new TranslationTextComponent("item." + Utils.MOD_ID +".mo_he.1").getString()+String.format("%.0f",getBeActivateTemprature())));
        tooltip.add(ITextComponent.getTextComponentOrEmpty(new TranslationTextComponent("item." + Utils.MOD_ID +".mo_he.2").getString()+String.format("%.0f",getBeRemoveTemprature())));
        tooltip.add(ITextComponent.getTextComponentOrEmpty(new TranslationTextComponent("item." + Utils.MOD_ID +".mo_he.3").getString()+String.format("%.0f",getBeActivateMaxTick()/20)));
        tooltip.add(ITextComponent.getTextComponentOrEmpty(new TranslationTextComponent("item." + Utils.MOD_ID +".mo_he.4").getString()+String.format("%.0f",getBeActivatePoint())));
    }
}

//木系一级魔核
class TunMuHuDeMoHe extends MoHe {
    /**被炼化温度*/
    public final static double Be_Activate_Temprature =300;
    /**被销毁温度*/
    public final static double Be_Remove_Temprature =800;
    /**允许炼化最大时间（耐久）*/
    public final static double Be_Activate_Max_Tick = 40*20;
    /**炼化完毕需要的点数*/
    public final static double Be_Activate_Point =50*20;
    /**
     * 魔核属性总数
     * <p>0 无§7</p>
     * <p>1 火§e</p>
     * <p>2 风§3</p>
     * <p>3 木§2</p>
     * <p>4 水§9</p>
     * <p>5 冰§b</p>
     * <p>6 土§g</p>
     * <p>7 岩§6</p>
     * <p>8 沙§e</p>
     * <p>9 雷§5</p>
     * <p>10暗§8</p>
     */
    public final static byte Attr =3;
    /**等阶*/
    public final static byte level =1;

    public TunMuHuDeMoHe() {
        super();
    }


    @Override
    public double getBeActivateTemprature() {
        return Be_Activate_Temprature;
    }

    @Override
    public double getBeRemoveTemprature() {
        return Be_Remove_Temprature;
    }

    @Override
    public double getBeActivateMaxTick() {
        return Be_Activate_Max_Tick;
    }

    @Override
    public double getBeActivatePoint() {
        return Be_Activate_Point;
    }

    @Override
    /**
     * 魔核属性总数
     * <p>0 无§7</p>
     * <p>1 火§e</p>
     * <p>2 风§3</p>
     * <p>3 木§2</p>
     * <p>4 水§9</p>
     * <p>5 冰§b</p>
     * <p>6 土§g</p>
     * <p>7 岩§6</p>
     * <p>8 沙§e</p>
     * <p>9 雷§5</p>
     * <p>10暗§8</p>
     */
    public byte getAttr(){
        return Attr;
    }

    @Override
    /**属性*/
    public byte getLevel(){
        return level;
    }
}